//
//  ZXTabBarController.m
//  qianke
//
//  Created by ZX on 2017/6/23.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXTabBarController.h"
#import "ZXNavigationController.h"
#import "ZXLoginRegisterViewController.h"
#import "ViewController.h"
#import "ZXMyController.h"
#import "ZXTabBar.h"
@interface ZXTabBarController ()<UITabBarControllerDelegate>
@end

@implementation ZXTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;

    [self setupTabBar];
    [self setupItemAttrs];
    ViewController * vc1 = [ViewController new];
    vc1.title = @"销售机会";
    vc1.tabBarItem.image = [UIImage imageNamed:@"销售机会_normal"];
    vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"销售机会_click"];
    ZXMyController * vc2 = [ZXMyController new];
    vc2.title = @"我的";
    vc2.tabBarItem.image = [UIImage imageNamed:@"我的_normal"];
    vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"我的_click"];
    ZXNavigationController * nav = [[ZXNavigationController alloc]initWithRootViewController:vc1];
    ZXNavigationController * nav2 = [[ZXNavigationController alloc]initWithRootViewController:vc2];
    
   
   
    [self addChildViewController:nav];
    [self addChildViewController:nav2];
    my_AppDelegate.isyididenglu=1;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(backToLogin) name:@"backToLogin" object:nil];

}
-(void)backToLogin{
    NSLog(@"回到登录");
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    NSUInteger i = tabBarController.selectedIndex;
    [dic setObject:[NSString stringWithFormat:@"%lu",(unsigned long)i] forKey:selectedIndexStr];
    [[NSNotificationCenter defaultCenter]postNotificationName:selectedIndexStr object:nil userInfo:dic];
    NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex);
}
- (void)setupTabBar
{
    [self setValue:[[ZXTabBar alloc] init] forKeyPath:@"tabBar"];
}
- (void)setupItemAttrs
{
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:tabbarfontNumber];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = baseLittleBlueColor;
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
